import Toast from '../../@vant/weapp/toast/toast';
import {IMG_PATH,apiList,ApiRootUrl} from '../../config/index.js'
import {timestamp2time,formatTime,request,Modal,SuccessTosat} from "../../utils/util"
//获取应用实例
const app = getApp()
Page({
  data: {
    IMG_PATH:IMG_PATH,
    statusBarHeight:'',
    width:wx.getSystemInfoSync().windowWidth,
    active:0,
    loadingFlag:false,
    userInfo: {},
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    //绑定宫格图片地址和文字
    dataList:[],
    customFlag:false,
    value:'',
    infoList:[],
    imageurlList:[],
    topbg:"rgba(0,0,0,0)",
  },
  onLoad: function () {
    this.setData({
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight']
    })
    let dataList = [
      {
      imgUrl:`/icon/fuwuzixun.png`,
      textValue:'服务咨询',
      navigateUrl:""
    },
    {
      imgUrl:`/icon/renyuanguanli.png`,
      textValue:'人员管理',
      navigateUrl:"../companyperson/companyperson"
    },
    {
      imgUrl:`/icon/weijidengji.png`,
      textValue:'违纪登记',
      navigateUrl:""
    },
    {
      imgUrl:`/icon/yunduanxuncha.png`,
      textValue:'云端巡查',
      // navigateUrl:""
      navigateUrl:"/pages/company/cloudPatrol/index"
    },{
      imgUrl:`/icon/jiaripaiban.png`,
      textValue:'假日排班',
      navigateUrl:"/pages/company/holiday/query/index"
    },
    {
      imgUrl:`/icon/wodexiaoxi.png`,
      textValue:'我的信息',
      navigateUrl:""
    },
    {
      imgUrl:`/icon/zhaopingdengji.png`,
      textValue:'招聘登记',
      navigateUrl:""
    }
    ];
    let imageurlList = [{
      id:'1',
      url:`${IMG_PATH}/center/qiye_lunbo.png`
    },{
      id:'2',
      url:`${IMG_PATH}/center/qiye_lunbo.png`
    },{
      id:'3',
      url:`${IMG_PATH}/center/qiye_lunbo.png`
    }];
    let userinfo = wx.getStorageSync('userinfo');
    this.getLabourList(userinfo.componentCode)
    this.setData({
      dataList:dataList,
      imageurlList:imageurlList
    })
  },
  onChange(event) {
    console.log(event.detail)
    if(event.detail == 2){
      console.log("点击新建")
    }else{
      this.setData({ active: event.detail });
    }
    
  },
  newAddTap(event){
    console.log("点击新建")
  },
  //点击信息触发事件
  msgTap(){
    return
    wx.requestSubscribeMessage({
      tmplIds: ['8Dqe1JDHYbv4SP4bGBgIL6a9oS9RIbQlkOaqGt0QNUw','kPrOW5nKcf2_gYzpUkn_HX_O3lIzfCmExMfCKHvvjU8','ddS_T-m_ygoysenu0MV-tq4ZrKugvEyg80aZgf9b9iA'],
      success (res) {
        console.log("-------->",res)
        Toast.loading({
          message: '加载中...',
          mask: true,
          duration: 0,
          forbidClick: true,
        });
        let openId = wx.getStorageSync("openId");
        let params={
          openId:openId,
          templateId:'ddS_T-m_ygoysenu0MV-tq4ZrKugvEyg80aZgf9b9iA',
          page:'/pages/authorizedInfo/authorizedInfo'
        }
       let url= `${ApiRootUrl}/labor/sendTest`;
        request(url,params,"POST").then(res =>{
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'success',
            message: '成功',
          })
        }).catch(err =>{
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: err.message,
          });
        })
      },
      fail(err){
        console.log("-------->",err)
      }
    })
   
  },
  /**
   * 未读消息页面跳转函数
   */
  tomessage(){
   
  },
  getLabourList(code) {
    request(apiList.getLabourList + "?componentCode=" + code, {}, "GET").then(res => {
      let columns = [];
      res.data.forEach((item) => {
        columns.push({
          id: item.orgCode,
          text: item.labourName
        })
      })
      console.log("columns==>",columns,res)
      let obj = {
        id:"",
        text:"全部"
      }
      columns.unshift(obj)
      app.globalData.companyList = columns
    }).catch(err => {
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  //点击搜索框触发事件
  onSearch(event){
    Toast(`${event.detail}`);
    console.log(event)
  },
  //点击图片触发事件
  imageTab(event){
    console.log(event.target.dataset.id);
  },
  //监听用户下拉刷新事件
  onPullDownRefresh(){
    wx.showNavigationBarLoading();
    setTimeout(function(){
      wx.hideNavigationBarLoading(); //完成停止加载图标
      wx.stopPullDownRefresh();
    },5000)
  },
   /**
   * 页面滑动监听
   */
  onPageScroll:function(e){
    console.log(e.scrollTop)
    if(e.scrollTop >10){
      this.setData({
        topbg:"#ACDAC3"
      })
    }else{
      this.setData({
        topbg:"rgba(0,0,0,0)"
      })
    }
  },

})
